package com.glsc.ngateway.common.api.ldap.resp;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.glsc.ngateway.common.api.common.enums.AppEhrStatus;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author gaojc
 * @Date: 2021/9/16 14:15
 * @Description:
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@ToString
public class AppEhrResponse<T> implements Serializable {
    private static final long serialVersionUID = 3476657283941250441L;
    private int status;
    private String errorMsg;
    private String userTip;
    private T data;

    public static AppEhrResponse<?> instanceOfSuccss() {
        AppEhrResponse<Object> response = new AppEhrResponse<>();
        response.setStatus(AppEhrStatus.Success.getErrorCode());
        response.setErrorMsg("SUCCESS");
        response.setData(new ArrayList<String>());
        return response;
    }

    public static AppEhrResponse<?> instanceOfSuccss(String msg) {
        AppEhrResponse<?> response = new AppEhrResponse<>();
        response.setStatus(AppEhrStatus.Success.getErrorCode());
        response.setErrorMsg(msg);
        return response;
    }

    public static <T> AppEhrResponse<T> instanceOfSuccss(T data) {
        AppEhrResponse<T> response = new AppEhrResponse<>();
        response.setStatus(AppEhrStatus.Success.getErrorCode());
        response.setErrorMsg("SUCCESS");
        response.setData(data);
        return response;
    }

    public static AppEhrResponse<?> instanceOfFail(String errorMsg, String userTip) {
        AppEhrResponse<?> response = new AppEhrResponse<>();
        response.setStatus(AppEhrStatus.Fail.getErrorCode());
        response.setErrorMsg(errorMsg);
        response.setUserTip(userTip);
        return response;
    }

    public boolean isSuccess(){
        return Objects.nonNull(this.status) && AppEhrStatus.Success.getErrorCode() == this.status;
    }
}

